import { Geometry } from "./Geometry";
import { any, all, has } from "../core/logic";
import { process } from "../process/worker/process";
/**
 * @class
 * @memberof w.geometry
 */
class CubeGeometry extends Geometry {
  /**
   * 立方体构造方法
   * @param {*} opts
   * @param {Number} opts.size 【可选值】立方体尺寸，缺省值：[1,1,1]。
   * @param {Boolean} opts.back 【可选值】是否开启后台线程构造圆，缺省值：true，在后台进行解析。
   * @example
   * let c=new w.geometry.CubeGeometry({size:[1,1,1]});
   */
  constructor(opts = {}) {
    super(opts);
    this.type = "CubeGeometry";
    this.position = null;
    this._size = any(opts.size, [1,1,1]);
    this.back = any(opts.back, false);
    this.createCube();
  }
  set back(v){
    this._back = v;
    return this;
  }
  get back(){
    return this._back;
  }
  set size(v){
    this._size = v;
    this.createCube();
    return this;
  }
  get size(){
    return this._size;
  }
  createCube() {
    if (all(has(this.size))) {
      let info = { back: this.back, size: this.size, type: "createCube" }
      process(info, (message) => {
        let { position, indices } = message.data;
        this.position = new Float32Array(position);
        this.indices = new Uint32Array(indices);
      })
    }
  }
}

export { CubeGeometry }
